package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default()

	// POST http://localhost:8080/addstudent HTTP/1.1
	engine.POST("/addstudent", func(context *gin.Context) {
		path := context.FullPath()
		fmt.Println(path)

		var person Person
		if err := context.ShouldBindJSON(&person); err != nil {
			log.Fatal(err.Error())
			return
		}

		fmt.Println(person.Name)
		fmt.Println(person.Sex)
		fmt.Println(person.Age)

		context.String(http.StatusOK, "添加记录 ,"+person.Name)

	})

	engine.Run()
}

type Person struct {
	Name string `json:"name,omitempty" xml:"name" form:"name"`
	Sex  string `json:"sex,omitempty" xml:"sex" form:"sex"`
	Age  string `json:"age,omitempty" xml:"age" form:"age"`
}
